﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    internal class ComputeRotationMartix
    {
        // 旋转点的方法
        // 固定的6组 x, y 值
        private readonly double[,] fixedPoints = new double[,]
        {
        { -23.0000, 27.5000},
        { -27.0000, 27.5000},
        { -31.0000, 27.5000 },
        { -35.0000, 27.5000 },
        { -39.0000, 27.5000 },
        { -43.0000, 27.5000 }
        };

        // 旋转点的方法
        public Tuple<double, double> RotatePoint(double x, double y, double theta, bool clockwise = false)
        {
            // 将角度转换为弧度
            double thetaRad = Math.PI * theta / 180.0;

            // 根据旋转方向选择旋转矩阵
            double cosTheta = Math.Cos(thetaRad);
            double sinTheta = Math.Sin(thetaRad);

            double[,] rotationMatrix;
            if (clockwise)
            {
                rotationMatrix = new double[,]
                {
                { cosTheta, sinTheta },
                { -sinTheta, cosTheta }
                };
            }
            else
            {
                rotationMatrix = new double[,]
                {
                { cosTheta, -sinTheta },
                { sinTheta, cosTheta }
                };
            }

            // 计算新坐标
            double newX = rotationMatrix[0, 0] * x + rotationMatrix[0, 1] * y;
            double newY = rotationMatrix[1, 0] * x + rotationMatrix[1, 1] * y;

            return Tuple.Create(newX, newY);
        }

        // 批量计算并返回结果
        public List<Tuple<double, double>> RotateFixedPoints(double theta, bool clockwise = false)
        {
            var rotatedPoints = new List<Tuple<double, double>>();

            for (int i = 0; i < fixedPoints.GetLength(0); i++)
            {
                double x = fixedPoints[i, 0];
                double y = fixedPoints[i, 1];

                // 旋转每个固定点
                var rotatedPoint = RotatePoint(x, y, theta, clockwise);
                rotatedPoints.Add(rotatedPoint);
            }

            return rotatedPoints;
        }
    }

}
